#ifndef __GGEAR_FILE_STREAM_H
#define __GGEAR_FILE_STREAM_H

#include "ggear_stream.h"
#include "ggear_string.h"
#include <stdio.h>

namespace ggear
{
	namespace io
	{
		class FileStream : public Stream
		{
		public:
			enum FileAccessMode
			{
				//! Read an existing file 
				FileAccessMode_Read = 0x01,
			
				//! Create a new file for writing 
				FileAccessMode_Write = 0x02,
			
				//! Start writing at the end of file
				FileAccessMode_Append = 0x04,

				//! Reading from or writing into existing file
				FileAccessMode_ReadEx = 0x08,

				//! Create a new file for writing / reading
				FileAcessMode_WriteEx = 0x10,

				//! Reading from the beginning of file or writing to the end of file 
				FileAccessMode_AppendEx = 0x20,
			};

		public:
			//! Open file stream from file
			FileStream(const glb::String& _path, FileAccessMode _mode);

			//! Destructor
			~FileStream();

			//! Return size of data stream
			u32 Size();

			//! Return the read/write cursor of this stream
			u32 Position();

			//! Read data from stream
			u32 Read(u32 _size, u8* _dst);

			//! Write data to stream
			u32 Write(u32 _size, u8* _src);

			//! Set position in current stream
			u32 Seek(u32 _offset, b8 _fromBeg = false);

			//! Close the data stream
			void Close();

		private:
			FILE* mFile;
			u32 mSize;
			u8 mMode;
		};
	}
}

#endif//__GGEAR_FILE_STREAM_H